Jai’s Weblog – Tech, Security & Fun…

Tech, Security & Fun…

  • Jaibeer Malik

    Jaibeer Malik
  • View Jaibeer Malik's profile on LinkedIn
  • Subscribe

  • Feedburner

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 40 other subscribers
  • Archives

  • Categories

  • Stats

    • 426,566
  • Live Traffic

Code Quality – Learn: OOPs, Desing Patterns, Clean Code and Refactoring

Posted by Jai on April 12, 2009

This article covers the second part of the series of articles Code Quality – Learn, Measure and Organize Awareness which is about the Code Quality – Learning code quality aspects, Using different code quality Measurement Tools and How to organize the awareness with in the team . Here we will discuss about the learning the fundamentals like OOPs concepts and Design Patterns, writing the clean code and how to approach to remove the bad smells from the code.

1. Focus on Fundamentals – OOPs and Design Patterns

2. How to write clean code – Clean Code

3. Figure out WTFs and improve code quality – Refactoring

1. Focus on Fundamentals – OOPs and Design Patterns

Looking at the history of Object Oriented Programming, it has come a long way and now a days, hopefully no one will neglect the importance and vast usage of these concepts in every system.

Importance:

Well in a way, Object-Oriented Design is a science and an art at the same time. Becoming a master of object-oriented technology would require experience and time. To give it a start have a look at the classic design patterns that have laid the foundation of object-oriented design, Design Patterns: Elements of Reusable Object-Oriented Software.

Material:

Lot of times many of the developer wonder that why to use these patterns, when to use and how to use them. Look for something which helps you to understand the patterns with the help of aids, models, examples, and discussions. Something like Head First Design Patterns.

Games:

Understanding the patterns in a way of conversation, discussion and solution for a problem would help you more to remember the idea behind it. There are people who plan it different way to help you with it in different ways, may be reading out the content like a lecture or to make it more interesting and learning friendly, you can also try it in the form of games. Like the Design Patterns Playing Cards using which you can try the learning part in the form of games, like Patterns Poker, Name That Pattern etc. which will help you to understand, learn and remember it in better way.

Use:

The responsibility now lies on you that how do you use these in the software development. Every software system has it own problem and solution they are trying to solve.

2. How to write clean code – Clean Code

In general terms we can say that the quality lies in the eyes of the beholder. It depends a lot on the individual perspective that how do you perceive the code quality. But think of it if someone else is reading or working on your code. There are some standards and principles which states whether the piece of code is of good or bad quality in context of the problem. That is what we will discuss here that how you can improve the awareness about these.

What is the main reason that developers write bad code? It varies from case to case like tight deadlines, motivation or may be lack of awareness. Many a times developers are not aware that what is the best way to put the solution in terms of lines of code.

The topic has been talked about many a times and by different people like Writing Clean Code or 7 tips on writing clean code

The one book which can give you more insight and explaining the real problems and context based solutions which I personally like is the Clean Code. For review please feel free to have a look at this Book Review and also very interesting comparison Clean Code vs. Implementation Pattern. And certainly few more enthusiastic who even say  Get it. Read it. Learn it. Then live it!.

The well illustrated examples, solutions in the context of the problems and the Heuristic Smells chapter can give you enough insight and can definitely help you to be a good if not great programmer.

3. Figure out WTFs and improve code quality – Refactoring

WTFs (Bad Smells)

Funny and irritating at the same time, what does it mean WTFs in the code.

The WTFs are the “Bad Smells” in the code which helps us recognize when we have a problem.

measurement-of-code-quality

Few questions that may come into your mind:

  • Why to put WTF?
  • How to find out WTFs?
  • What to do with WTFs?

As I stated it earlier also that no developer introducing these bad smells intentionally. Either you are not aware about the right approach or may be ignorance or time pressure.

To figure out these bad smells, either to take care when you are writing the code first time or when you revisit the code second time, may be during fixing bugs or adding new functionality.

Well remove the WTFs. Figure out what is the better  solution, if not the best. Refactoring is the solution for it.

Refactoring

A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.

Refactoring improves the design of your softwares, make it easy to read and modify and help you to find bugs.

There are plenty of books and documents available to help you to understand refactoring and to understand why, when and how to do it.

The one book I liked reading very much and would like to recommend is Refactoring: Improving the Design of Existing Code.

The starting chapter itself explains the common problems you must have seen in the code many a times and then refactoring the code step by step to reach a solution where in the end you can say it is good code. The common Bad Smells chapter will give you enough idea to figure out the WTFs in your existing code or the next time you are going to code. The different refactoring techniques will give you hold on the topics like the design patterns.

Refactoring Catalog

As in the case of patterns, refactorings  also have names  in order to crystallize  the idea and help us remember it.

For the latest and updated catalog look at the online Refactoring Catalog.

Refactoring Tools

The commonly used IDE like Eclipse and IntelliJ comes with inbuilt refactoring capabilities. These days most of the development tools come with some sort of refactoring support. For more, have a look at Refactoring Java Tools.

There is no single book which can make you master of it but certainly can help you to have better understanding of the concepts and ideas behind it so that next time you put few lines of code you know the pros and cons.

One Response to “Code Quality – Learn: OOPs, Desing Patterns, Clean Code and Refactoring”

  1. […] https://jaibeermalik.wordpress.com/2009/04/12/code-quality-learn-oops-desing-patterns-clean-code-and-… […]

Leave a comment